package com.fpx.order.plat.bussiness.plat.smt.task;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fpx.order.plat.bussiness.dao.log.IPullOrderLogDao;
import com.fpx.order.plat.bussiness.entity.CustomerShop;
import com.fpx.order.plat.bussiness.plat.base.PlatOrderCurrentJob;
import com.fpx.order.plat.bussiness.plat.smt.service.SmtDeliveryOrderHandler;
import com.fpx.order.plat.bussiness.system.PlatConstants;

@Component
public class SmtDeliveryOrderJob extends PlatOrderCurrentJob {

	private final static Logger LOGGER = Logger
			.getLogger(SmtDeliveryOrderJob.class);

	@Autowired
	private SmtDeliveryOrderHandler smtDeliveryOrderHandler;

	@Autowired
	private IPullOrderLogDao pullOrderLogDao;

	/**
	 * 定时任务
	 */
	public void exec() {
		LOGGER.info("【速卖通 smt】 自动平台订单开始.....");
		initMeodth(PlatConstants.ORDER_SOURCE_SMT);
		List<CustomerShop> customerLst = super.getCustomers();
		if (!org.springframework.util.StringUtils.isEmpty(customerLst)) {
			// 遍历商家和店铺
			for (CustomerShop customer : customerLst) {
				String cm_id = customer.getCm_id();
				String cs_id = customer.getCs_id();
				try {
//					if("550277".equals(cm_id)&&"481".equals(cs_id)){
						smtDeliveryOrderHandler.deliveryOrder(customer, 0);
//					}
				} catch (Exception ex) {
					LOGGER.error("【SMT】---商家:[" + cm_id + "]-商铺ID:[" + cs_id+ "]-【异常信息】: " + ex.getMessage());
				}
			}
		}
		LOGGER.info("【速卖通 smt】 自动平台订单结束");
	}
}
